<template>
	<view class="wrapper">
		<view class="navition">
			<video src="" controls></video>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//渲染的视频
				videoSrc: {},
				autoplay: 'false',
				videoList: [{
						a: 0,
						title: "女性全检",
						video: "../../static/video/body_w_zhunbei.mp4",
						videos: "../../static/video/body_w_jieshu.mp4"
					},
					{
						a: 1,
						title: "男性全检",
						video: "../../static/video/body_m_zhunbei.mp4",
						videos: "../../static/video/body_m_jieshu.mp4"
					},
					{
						a: 2,
						title: "女生面部检",
						video: "../../static/video/face_w_zhunbei.mp4",
						videos: "../../static/video/face_w_jieshu.mp4"
					},
					{
						a: 3,
						title: "男生面部检",
						video: "../../static/video/face_m_zhunbei.mp4",
						videos: "../../static/video/face_m_jieshu.mp4"
					},
				]
			}
		},
		onLoad(option) {
			console.log(option, "option")
			const id = optipn.id * 1
			console.log(id, "id")
			this.videoList.forEach((item, key) => {
				console.log(item, "item")
				if (item.a === id) {
					this.videoSrc.video = item.video
					this.videoSrc.id = item.a
					this.autoplay = true
				}
			})
		},
		methods: {
			videoTimeUpdateEvent(e) { //播放进度改变
				let currentTime = Number(e.detail.currentTime);
				let durationTime = Number(e.detail.currentTime);
				if (currentTime >= durationTime) {
					uni.navigateTo({
						url: ""
					})
				}
			},
			videoClick(e) {
				uni.navigateTo({
					url: ""
				})
			}
		},
		onReady() {
			const that = this;
			//防止切图成白屏
			setTimeout(function() {
				that.toImage();
			}, )
		},
		created(){
			console.log('123')
		},
		mounted(){
			const query=uni.createSelectorQuery().in(this);
			query.select('#bg').boundingClientRect(data=>{
				console.log(data)
				this.widthH=data.width;
				this.heightH=data.height;
			}).exec();
		},
		methods:{
			qrcode(){
				let url='http://app-abc.itipool.co/?code='+this.codes
				this.img=QR.createQrCodeImg(url,{
					size:parseInt(280)//二维码大小
				})
			},
			toImage(){
				const that=this;
				/*获取屏幕信息*/
				let ws=this.$mp.page.$getAppWebview();
				console.log(ws,'123')
				let bitmap=new plus.nativeObj.Bitmap('test');
				//将webview内容绘制到Bitmap对象中
				ws.draw(
					bitmap,
					function(e){
						/*获取base64*/
						that.test=bitmap.toBase64Data();
						/*加载base64编码*/
						bitmap.loadBase64Data(
							bitmap.toadBase64Data(),
							function(){
								console.log('加载Base64图片数据成功');
								/*保存图片*/
								bitmap.save(
									'_doc/share.jpg',{},
									async(i)=>{
										console.log('保存图片成功'+JSON.stringify(i));
										uni.saveImageToPhotosAlbum({
											filePath:i.target,
											success:function(){
												/*清除*/
												bitmap.clear();
												that.$refs.uToast.show({
													title:'保存成功,请到相册中查看',
													type:'success',
												})
											},
											fail(e){
												that.$refs.uToast.show({
													title:'保存失败'+e,
													type:'error',
												})
											}
										})
									},
									function(e){
										conaole.log('保存图片失败：'+JSON.stringify(e));
									}
								);
							},
							function(){
								console.log('加载Base64图片数据失败：'+JSON.stringify(e));
							}
						);
					},
					function(e){
						console.log('截屏绘制图片失败：'+JSON.stringify(e));
					},{
						check:true,//设置为检测白屏
						clip:{
							top:'0px',
							left:'0px',
							height:this.heightH ,
							width:this.widthH
						}
					}
				)
			}
		}
	}
</script>

<style>
	.wrapper {
		width: 600px;
		height: 350px;
		background: #ffff7f;
		color: write;
		font-size: 36px;
		border: 1px solid #36BB6B;
	}
</style>
